/**
* @fileoverview HQ cookie数据处理
* @author zhang jianbin
* @version 1.0
*/

/**
 * cookie类
 * @namespace
 */
HQ.cookie = {
	/**
	 * 设置一个cookie
	 * @param {String} name cookie名称
	 * @param {String} value cookie值
	 * @param {Number} day 存活时间，单位:毫秒
	 */
	set:function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	
	/**
	 * 获取指定名称的cookie值
	 * @param {String} name cookie名称
	 * @return {String} 获取到的cookie值
	 */
	get: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
},
	
	/**
	 * 删除指定cookie,复写为过期
	 * @param {String} name cookie名称
	 * @param {String} domain 所在域
	 * @param {String} path 所在路径
	 */
	del: function(name) {
		createCookie(name,"",-1);
	}
};